package ca.ualberta.cs.CLRDB;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public abstract class EntityRelManagement {
	protected String mainTableName ;
	protected int numOfCols;
	
	public void printAll(){
		Connection con = DatabaseController.connectToDB();
		   try{
			   Statement statement = con.createStatement();
			   ResultSet res = statement.executeQuery("SELECT * FROM "+mainTableName);
			   while(res.next()){
				   for(int i = 1 ; i <= numOfCols ; i++ )
					   System.out.print(res.getString(i) + " , ");
				   System.out.println();
			   }
		   }catch (SQLException e) {
				System.err.println("SQLException:");
				while(e!=null) {
					System.err.println ("Error msg: " + e.getMessage());
					System.err.println ("SQLSTATE: " + e.getSQLState());
					System.err.println ("Error code: " + e.getErrorCode());
					e.printStackTrace();
					e = e.getNextException();
				}			
			} catch (Exception e) {			
				e.printStackTrace();			
			} 
		   
	}
	public abstract void initialize(Statement statement) throws SQLException;	
	
}
